<?php
apf_require_file("Smarty.class.php","smarty");

abstract class AbstractPage  {

    protected $smarty;

    public function  __construct(){
        define('SMARTY_ROOT',dirname(__FILE__));
       // var_dump(SMARTY_ROOT);exit;
        $tpl = new Smarty();
        $tpl->template_dir = SMARTY_ROOT."/tpl/";
        $tpl->compile_dir = SMARTY_ROOT."/tpl_c/";
        $tpl->caching=false;
        // $tpl->cache_lifetime=60*60*24;
        $tpl->left_delimiter = '{';
        $tpl->right_delimiter = '}';
        $common_domain =  APF::get_instance()->get_config('common_domain');
        $tpl->assign('common_domain',$common_domain);
        $matches = $this->get_request()->get_router_matches();
        $base_domain = APF::get_instance()->get_config('base_domain');
        $current_nav = $matches[0];
        if (!preg_match("#/$#", $current_nav)) {
            $current_nav.="/";
        }

        if( in_array($current_nav,array('/attendance/','/myannual/','/myapply/','/more/') ) ){
            $current_nav = "/";
        }elseif(in_array($current_nav,array('/unaudit/') )){
            $current_nav = "/audit/";
        }

        $tpl->assign('current_nav',$base_domain.$current_nav);
        $this->smarty = $tpl;
    }

    protected function get_view(){
        $data = APF::get_instance()->get_request()->get_attributes();
        if($data) {
            foreach($data as $key => $val) {
                $this->smarty->assign($key, $val);
            }
        }
        return $this->get_sub_view();
    }

    public function execute(){

        $this->get_view();

    }

    protected function get_request(){
        return APF::get_instance()->get_request();
    }

    protected function get_response(){
        return APF::get_instance()->get_request();
    }

}

?>